dojo.provide("ctrlspace.ui.MenuBar");
dojo.require("ctrlspace.core.Plugin");
dojo.require("dijit.Toolbar");
dojo.declare("ctrlspace.ui.MenuBar", ctrlspace.core.Plugin, {
	// Attributes

	// Constructor
	constructor: function(properties) {
		dojo.safeMixin(this, properties);

		this.menus = {};
		var menubar = new dijit.Toolbar({
			region: "top",
			style: "height: 24px"
		});
		
		this.menuContainer = menubar;
		IDE.getUI().setMenuBar(this);
	},
	
	// Methods
	getMenu: function(menuId) {
		if (this.menus[menuId] == null) {
			return null;
		}
		return this.menus[menuId];
	},

	// Extension point function
	extend: function(id, menu) {
		if (menu.location == "default") {
			this.menuContainer.addChild(menu.actualMenu);
		} else {
			for (var i in this.menus) {
				if (this.menus[i] == menu.location) {
					this._insertAfter(dojo.byId(i), newMenu);
				}
			}
		}

		this.menus[id] = menu;
	},

	_insertAfter: function(referenceNode, newNode) {
	    referenceNode.parentNode.insertBefore(newNode,referenceNode.nextSibling);
	}
});